<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
		<title></title>
		<link type="text/css" rel="stylesheet" href="/spider/static/css/admin.css"/>
		<script type="text/javascript" src="/spider/static/js/jquery-3.1.1.js"></script>
	</head>
	<body>
		<div id='z'>
			
			<div id='l'>
				
				<ul class="lb">
					<li><h1>管理操作</h1></li>
					<li data-toggle="o">
						<h2>发卡管理</h2>
					</li>
						<ul class="xl" id='o'>
						<li>查询/生成:
							<input type="number" placeholder="生成数量"/>
						</li>
						<li>卡密/类型:
							<select >
								<option value="1">1个月卡密</option>
								<option value="2">3个月卡密</option>
								<option value="3">10年卡密</option>
							</select>
							<input type="button" value="生成" data-T='1'/>
							<input type="button" value="查询" data-T='3'/>
						</li>
						</ul>
					<li data-toggle= "t"><h2>用户管理</h2></li>
					<ul class="xl" id='t'>
						<li>
							查找用户：<input type="number" placeholder="用户ID" id='userid'/>
						</li>
						<li>
							<input type="button" value="查找用户" data-T='2'/>
							<input type="button" value="获取常用IP"/>
							<input type="button" value="保存信息" data-T='4'/>
						</li>
					</ul>
					<li>
						
						<textarea id="notice" >{"one": "","tow": "", "three": "","four": ""}</textarea>
						<button id="sub">提交修改</button>
					</li>
				</ul>
				
			</div>
			
			<div id='r'>
				
				<ul class="lb">
					<li><h1>查询结果</h1></li>
					<li><h2>卡密：sadklasjdlaskjdlaksjdKLJLASJKDLAJSKD</h2></li>
				</ul>
			</div>
			
		</div>
		<script>
			//-----------全局按钮事件------------------
			$('input[type=button]').click(function(){
				var num=$('input[type=number]').val();
				var type=$(this).data('t');
				if(type=='1'){
					type=$("select option:selected").val();
				    $.get('{:url("savecard","","")}'+'/key/'+'{$key}'+'/num/'+num+'/type/'+type,function(data){alert(data)});
				}else if(type=='2'){
					$id=$('#userid').val();
					$.get("{:url('getuser','','')}"+'/key/'+'{$key}'+'/id/'+$id,function(data){
						$('#r>.lb').html('<li><h1>查询结果</h1></li>');
						$str='<li>用户ID:<p>'+data.id+'</p></li><li>用户名:<p contenteditable="true">'+data.username+'</p></li><li>VIP时间:<p contenteditable="true">'+data.vip+'</p></li><li>积分数:<p contenteditable="true">'+data.mark+'</p>点</li>';
						$('#r>.lb').append($str);
					})
				}else if(type=='3'){
					var $str='';
					type=$("select option:selected").val();
					$.get('{:url("sqlquery","","")}'+'/key/'+'{$key}'+'/num/'+num+'/type/'+type,function(data){
						$('#r>.lb').html('<li><h1>查询结果</h1></li>');
						$.each(data, function(i,n) {
							$str=$str+'<li><h2>卡密：'+n.card+'&nbsp类型：'+n.type+'</h2></li>';
						});
						$('#r>.lb').append($str);
					});
				}else if(type=='4'){
					var $str=[];
					$('.lb p').each(function(i){
						console.log('d');
						$str.push($(this).text());
					});
					
					$.post("{:url('saveuser','','')}"+'/key/'+'{$key}',{
						'username':$str[1],
						'vip':$str[2],
						'mark':$str[3],
						'id':$str[0]
					},function(data){
						alert(data);
					})
					
					
				}
			})
			//-------------列表下拉效果----------------
			$('#l>.lb>li').click(function(){
				var i='#'+$(this).data('toggle');
				console.log(i);
				$(i).slideToggle();
			})
			//--------------修改公告----------------
			$(function(){
				$('#sub').click(function(){
					var notice = $('#notice').val();
					$.post("{:url('notice','','')}"+'/key/'+'{$key}','notice='+notice,function(data){
						
					})
				})
			})
			
			
		</script>
	</body>
</html>
